<!--# layout("/common/layout.html",{"jsBase":"/js/plandata/major/"}){ -->
<form class="layui-form layui-form-pane" id="addForm"  lay-filter="editform">
    <input type="hidden" name="id" id="id" value="${tDPlanningData.id}">
    <input type="hidden" name="pId" id="pId" value="${pId}">
    <input type="hidden" name="provinceId" id="provinceId" value="${provinceId}">
<!--    <input type="hidden" name="majorTypeId" id="majorTypeId" value="${plandata.majorTypeId}">-->
<!--    <input type="hidden" name="" id="provinceId" value="${provinceId}">-->
    <br>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">专业名称</label>
                <div class="layui-input-block" style="width:512px">
                    <textarea name="majorName"  id="majorName" placeholder="请输入" class="layui-textarea" lay-verify="required">${tDPlanningData.majorName}</textarea>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">专业代码</label>
                <div class="layui-input-inline">
                    <input type="text" name="majorCode" id="majorCode" autocomplete="off" maxlength="50" class="layui-input" value="${tDPlanningData.majorCode}" lay-verify="required">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">招生人数</label>
                <div class="layui-input-inline">
                    <input type="text" name="plan" id="plan" autocomplete="off" maxlength="50" class="layui-input" value="${tDPlanningData.plan}" lay-verify="required|number">
                </div>
            </div>

        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">



            <div class="layui-inline">
                <label class="layui-form-label" >学年</label>
                <div class="layui-input-inline">
                    <input type="text" name="schoolyear" id="schoolyear" autocomplete="off" maxlength="50" class="layui-input" value="${tDPlanningData.schoolyear}" lay-verify="required|number">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label" >学费(元)</label>
                <div class="layui-input-inline">
                    <input type="text" name="cost" id="cost" autocomplete="off" maxlength="50" class="layui-input" value="${tDPlanningData.cost}">
                </div>
            </div>
        </div>
    </div>


    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">专业测评</label>
                <div class="layui-input-block" style="width:512px">
                    <textarea name="majorEvaluation"  id="majorEvaluation" placeholder="请输入" class="layui-textarea" >${tDPlanningData.majorEvaluation}</textarea>
                </div>
            </div>

        </div>
    </div>


    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block" style="width:512px">
                    <textarea name="remark"  id="remark" placeholder="请输入" class="layui-textarea" >${tDPlanningData.remark}</textarea>
                </div>
            </div>

        </div>
    </div>
    <layui:submitButtons id="majoraddButton" />
</form>
<!--#} -->
<script>
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','majorApi'], function(exports) {
    var form = layui.form;
    var majorApi = layui.majorApi;
    var index = layui.index;
    var isNew = true;
    <!--# if(!(isEmpty(tDPlanningDataJson))){  -->
    isNew = false;
    <!--# } -->
    // var remainCount =parseInt("${remainCount}") ;
    var plan =parseInt("${tDPlanningData.plan}");
    // if(isNew){
    //     $("#remainCount").val(remainCount);
    // }else{
    //     $("#remainCount").val(remainCount+plan);
    // }

    // $("#plan").blur(function(){
    //     var plan = ($("#plan").val());
    //     var remainCount = parseInt($("#remainCount").val());
    //     if(plan>remainCount){
    //         Common.info("招生人数不能大于剩余招生人数");
    //     }
    // });

    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#majoraddButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();

                var plan = ($("#plan").val());
                var remainCount = parseInt($("#remainCount").val());
                if(plan>remainCount){
                    Common.info("招生人数不能大于剩余招生人数");
                    return;
                }
                form.on('submit(form)', function(){
                    majorApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#majoraddButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();

    <!--# if(!(isEmpty(TDPlanningDataJson))){  -->
    var formJson = ${TDPlanningDataJson};
    form.val("editform",formJson);
    <!--# } -->


    $("#umId").val("${tDPlanningData.umId }");

    setBatch($("#year").val());

    //省份选择事件监听
    form.on('select(colFilter)', function(data){
        setBatch($("#year").val());
    });

    form.on('select(typeselect)', function(data){
        setBatch($("#year").val());
    });

    form.on('select(umIdFilter)', function(data){
       $("#univId").val(data.value.substring(0,5));
       $("#univName").val($("#umId").find("option:selected").text());
    });

    $("#year").blur(function(){
        setBatch($("#year").val());
    });

    function setBatch(year) {
        var id = $('#provinceId option:selected').val();
        var type = $('#majorTypeId option:selected').val();
        $.ajax({
            type: 'POST',
            url: "${ctxPath}/plandata/tDPlanningData/getBatch.json",
            data: {
                id:id,
                year:2018,
                type:type
            },
            dataType:'json',
            success: function(data){
                $("#batchId").html("");
                var option1 = $("<option>").val("").text("请选择");
                $("#batchId").append(option1);
                $.each(data, function(key, val) {
                    var option1 ;
                    if(val.value == "${tDPlanningData.batchId }"){
                        option1 = $("<option selected>").val(val.value).text(val.key);
                    }else{
                        option1 = $("<option>").val(val.value).text(val.key);
                    }
                    $("#batchId").append(option1);
                });
                form.render('select');

            }
        });
    }


});
</script>
